package com.sky.controlor;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;



/**
 * @author Administrator
 *
 */
@Controller
public class SuperControlor {
	
	@ExceptionHandler({Exception.class})
	  public ModelAndView exception(Throwable e){
		//把当前日期转为string类型
		Date d = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date = sdf.format(d);
		//给要接收信息的地址文件名
		File file = new File("d:/message.log");
		//打印流
		PrintStream ps;
		try {
			
			ps = new PrintStream(file);
			//把日期写入file
			ps.print(date);
			//将异常信息写入到file
			e.printStackTrace(ps);
		} catch (FileNotFoundException e1) {
			
			e1.printStackTrace();
		}
		//到错误页面
		  return new ModelAndView("error");
	  }
}
